import { useCreation } from "ahooks";

function useIdlePlugin(fetchInstance, fetchOptions) {
  useCreation(() => {
    fetchInstance.setState({ loading: true });
    if (fetchOptions.prefetchReady) {
      fetchInstance.runAsync();
    }
  }, [fetchOptions.prefetchReady]);

  return {
    onCancel() {
      fetchInstance.setState({ loading: true });
    },
  };
}

export default useIdlePlugin;
